/*
 * Copyright (c) 2015. 石头哥哥
 */

package com.comom.manager.kit.springQuartz;

import org.quartz.JobExecutionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.lang.reflect.Method;

/**
 * @author 石头哥哥</ br>
 *         Date:14-3-17</br>
 *         Time:下午8:02</br>
 *         Package:com.dc.gameserver.extComponents.Kit.springQuartz</br>
 *         Comment：重写QuartzJobBean      避免序列化异常
 */
public class ScheduleJob extends QuartzJobBean {

    private static ApplicationContext applicationContext;    //spring容器操作句柄
    private String targetObject;
    private String targetMethod;

    /**
     * spring初始化之后，set进来
     * @param fileSystemXmlApplicationContext spring 操作 句柄
     */
    public static void setSpringContext(FileSystemXmlApplicationContext fileSystemXmlApplicationContext) {
        applicationContext = fileSystemXmlApplicationContext;
    }

    /**
     * @param context
     */
    protected void executeInternal(JobExecutionContext context) {
        try {
            Object o = applicationContext.getBean(targetObject);
            Method m = o.getClass().getMethod(targetMethod, new Class[]{});
            m.invoke(o);
        } catch (Exception ignored) {
        }
    }

    /**
     * @param targetObject
     */
    public void setTargetObject(String targetObject) {
        this.targetObject = targetObject;
    }

    public void setTargetMethod(String targetMethod) {
        this.targetMethod = targetMethod;
    }

}
